import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';
import {CommonTool} from '../common/common.tool';
import {HTTP_URLS} from '../base/base-http.url';
import {environment} from '../../environments/environment';

@Injectable({
  providedIn: 'root'
})
export class HomeService {

  constructor(private http: HttpClient) {

  }

  /**
   * 退出登录
   */
  public logOut(): Observable<any> {
    if (!environment.openBackEnd) {
      return new Observable((observer) => {
        observer.next({});
      });
    }
    return this.http.delete<any>(HTTP_URLS.deleteCurrentToken);
  }

  /**
   * 修改密码
   */
  public updateCurrentUserPassword(req: { newPassword, password }): Observable<any> {
    return this.http.put<any>(HTTP_URLS.updateCurrentUserPassword, req);
  }

  /**
   * 获取用户信息
   */
  public getCurrentUser(): Observable<any> {
    if (!environment.openBackEnd) {
      return new Observable((observer) => {
        observer.next({});
      });
    }
    return this.http.get<any>(HTTP_URLS.getCurrentUser);
  }

}
